package com.palm.core.util.castor;

public class DoubleCastor implements Castor<Double> {
    public static final DoubleCastor instance=new DoubleCastor();
    private DoubleCastor(){};
    @Override
    public Double cast(Object v) {
        if(v==null){
            return 0D;
        }else if(v instanceof Number){
            return ((Number)v).doubleValue();
        }else{
            String str = v.toString();
            if(str.isEmpty()||"null".equals(str)||"undefined".equals(str)||"Infinity".equals(str)){
                return 0D;
            }else{
                try {
                    return Double.parseDouble(str);
                }catch (Exception e){
                    return 0D;
                }
            }
        }
    }
}
